﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace UIDesigner
{
    //[ToolboxBitmap(typeof(UILine), "Resources.UILine.ico"), Designer(typeof(UILineDesigner))]
    [ToolboxBitmap(typeof(UILine)), Designer(typeof(UILineDesigner))]
    public class UILine : Label
    {
        private string m_strDisplayName;
        private string m_strDisplayText = "分隔线";
        private UILineLineBorderStyle m_theLineBorderStyle;
        private UILineLineStyle m_theLineStyle;
        private int m_nLineLength = 2;

        public UILine()
        {
            base.SetStyle(ControlStyles.ResizeRedraw, true);
            this.LineStyle = UILineLineStyle.HorizontallyLine;
            this.LineBorderStyle = UILineLineBorderStyle.Line3D;
            this.BackColor = Color.Transparent;
            base.Height = this.m_nLineLength;
            this.AutoSize = false;
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            Border3DSide top = Border3DSide.Top;
            Border3DStyle etched = Border3DStyle.Etched;
            Rectangle empty = Rectangle.Empty;
            if (this.m_theLineStyle == UILineLineStyle.VerticallyLine)
            {
                top = Border3DSide.Left;
                empty = new Rectangle(0, 0, base.ClientRectangle.Width, base.ClientRectangle.Height);
            }
            else
            {
                top = Border3DSide.Top;
                empty = new Rectangle(0, 0, base.ClientRectangle.Width, base.ClientRectangle.Height);
            }
            if (this.m_theLineBorderStyle == UILineLineBorderStyle.LineSingle)
            {
                etched = Border3DStyle.Flat;
            }
            ControlPaint.DrawBorder3D(e.Graphics, empty, etched, top);
        }

        protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
        {
            if (this.LineStyle == UILineLineStyle.HorizontallyLine)
            {
                base.SetBoundsCore(x, y, width, this.m_nLineLength, specified);
            }
            else
            {
                base.SetBoundsCore(x, y, this.m_nLineLength, height, specified);
            }
        }

        [Browsable(false)]
        public override bool AutoSize
        {
            get
            {
                return base.AutoSize;
            }
        }

        public string DisplayName
        {
            get
            {
                return this.m_strDisplayName;
            }
            set
            {
                this.m_strDisplayName = value;
            }
        }

        [Browsable(false)]
        public string DisplayText
        {
            get
            {
                return this.m_strDisplayText;
            }
            set
            {
                this.m_strDisplayText = value;
            }
        }

        [Description("设置分隔线是3D线还是单线条."), Browsable(true), Category("外观")]
        public UILineLineBorderStyle LineBorderStyle
        {
            get
            {
                return this.m_theLineBorderStyle;
            }
            set
            {
                this.m_theLineBorderStyle = value;
                base.Invalidate();
            }
        }

        [Description("设置分隔线是横向线还是竖向线."), Category("外观"), Browsable(true)]
        public UILineLineStyle LineStyle
        {
            get
            {
                return this.m_theLineStyle;
            }
            set
            {
                int @long = this.Long;
                this.m_theLineStyle = value;
                this.Long = @long;
                base.Invalidate();
            }
        }

        [Description("设置分隔线长度."), Category("布局"), Browsable(true)]
        public int Long
        {
            get
            {
                if (this.m_theLineStyle == UILineLineStyle.VerticallyLine)
                {
                    return base.Height;
                }
                return base.Width;
            }
            set
            {
                if (this.m_theLineStyle == UILineLineStyle.VerticallyLine)
                {
                    base.Height = value;
                    base.Width = this.m_nLineLength;
                }
                else
                {
                    base.Width = value;
                    base.Height = this.m_nLineLength;
                }
                base.Invalidate();
            }
        }

        [Browsable(false)]
        public override string Text
        {
            get
            {
                return base.Text;
            }
        }

        public enum UILineLineBorderStyle
        {
            Line3D,
            LineSingle
        }

        public enum UILineLineStyle
        {
            HorizontallyLine,
            VerticallyLine
        }
    }
}

